package com.itheima.service;

import org.springframework.context.annotation.Bean;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.config.JmsListenerContainerFactory;
import org.springframework.jms.config.SimpleJmsListenerContainerFactory;
import org.springframework.stereotype.Component;

import javax.jms.ConnectionFactory;

/**
 * Created by crowndint on 2018/10/1.
 */

/*
   消息订阅者
 */
@Component
public class MsgSubscriber {

    @JmsListener(destination = "msgDestination", containerFactory = "mJmsListenerContainerFactory")
    public void subscribe(String text) {

        System.out.println("接受到订阅的消息:"+text);
    }

    @Bean
    JmsListenerContainerFactory mJmsListenerContainerFactory(ConnectionFactory connectionFactory) {

        SimpleJmsListenerContainerFactory containerFactory = new SimpleJmsListenerContainerFactory();
        containerFactory.setConnectionFactory(connectionFactory);
        containerFactory.setPubSubDomain(true);
        return containerFactory;
    }


}
